/*
 * Created by SharpDevelop.
 * User: taras
 * Date: 25.12.2008
 * Time: 19:33
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;
using System.Linq;

namespace N2.Explorer
{
	using Edit;
	using Services;

	public partial class MainForm : Form, IStudioForm
	{
		public MainForm()
		{
			InitializeComponent();
			
			Array.ForEach(
				ConfigurationService.Container.ResolveAll<IStudioService>(),
				_svc => _svc.Initialize(this));

			this.ts.SuspendLayout();

			this.ts.Items.AddRange((
				from _plugin in Context.Current.EditManager.GetPlugins<ToolbarPluginAttribute>(Thread.CurrentPrincipal)
				orderby _plugin.SortOrder
				select new ToolStripButton(
						_plugin.Title,
						string.IsNullOrEmpty(_plugin.IconUrl)
							? null
							: Image.FromFile(VirtualPathUtility.ResolveUrl(_plugin.IconUrl))) {
					DisplayStyle = ToolStripItemDisplayStyle.Image,
					ImageTransparentColor = Color.Magenta,
					Name = _plugin.Name,
					Size = new Size(23, 22),
				}).ToArray());

			this.ts.ResumeLayout(false);
			this.ts.PerformLayout();
		}

		#region IStudioForm Members

		PropertyGrid IStudioForm.PropertyGrid { get { return this.pg; } }

		ContextMenuStrip IStudioForm.ContextMenu { get { return this.ctxMenu; } }

		TreeView IStudioForm.TreeView { get { return this.tv; } }

		ToolStrip IStudioForm.Toolbar { get { return this.ts; } }
		
		ImageList IStudioForm.ImageList { get { return this.imgListForTreeView; } }

		#endregion
	}
}
